package com.zut.demo1.service.impl;

import com.zut.demo1.dao.ClassinglogMapper;
import com.zut.demo1.model.Classinglog;
import com.zut.demo1.model.ClassinglogExample;
import com.zut.demo1.service.ClassinglogService;
import com.zut.demo1.utils.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class ClassinglogServiceImpl implements ClassinglogService {

    @Autowired
    private ClassinglogMapper classinglogMapper;

    @Override
    public List<Classinglog> getAll(Classinglog classinglog) {
        System.out.println("Impl");
        ClassinglogExample example = new ClassinglogExample();
        ClassinglogExample.Criteria criteria = example.createCriteria();

        if (classinglog.getOptname()==""){
            criteria.andOpttimeLike(classinglog.getOpttime()+"%");
            criteria.andOptcodeBetween("1000","9999");
        }else{
            criteria.andOpttimeLike(classinglog.getOpttime()+"%");
            criteria.andOptnameLike("%"+classinglog.getOptname()+"%");
            criteria.andOptcodeBetween("1000","9999");
        }

        return classinglogMapper.selectByExample(example);
    }

    @Override
    public int countfangshi1(String times) {
        ClassinglogExample example = new ClassinglogExample();
        ClassinglogExample.Criteria criteria = example.createCriteria();

        criteria.andOptcontextEqualTo("刷卡");

        criteria.andOpttimeLike(times+"%");

        return classinglogMapper.countByExample(example);
    }

    @Override
    public int countfangshi2(String times) {
        ClassinglogExample example = new ClassinglogExample();
        ClassinglogExample.Criteria criteria = example.createCriteria();
        criteria.andOpttimeLike(times+"%");

        int num = classinglogMapper.countByExample(example);
        System.out.println("num:"+num);
        return num;
    }

    @Override
    public List<Classinglog> getrmName(String times) {
        ClassinglogExample example = new ClassinglogExample();
        ClassinglogExample.Criteria criteria = example.createCriteria();
        criteria.andOpttimeLike(times+"%");

        return classinglogMapper.selectByExample(example);
    }

    /*
    *   文件导出
     */
    @Override
    public List<Classinglog> findAllClassinglogByCondition(Classinglog classinglog) {
        ClassinglogExample example = new ClassinglogExample();
        ClassinglogExample.Criteria criteria = example.createCriteria();
        criteria.andOpttimeLike(classinglog.getOpttime()+"%");
        criteria.andRmnameLike(classinglog.getRmname()+"%");
        criteria.andOptcontextLike(classinglog.getOptcontext()+"%");

        return classinglogMapper.selectByExample(example);
    }

    @Override
    public int deleteById(Classinglog classinglog) {

        return classinglogMapper.deleteByPrimaryKey(classinglog.getId());
    }

    //保存数据
    @Override
    public int saveImportExcel(Classinglog classinglog) {
        return classinglogMapper.insert(classinglog);
    }

    //判断数据是否存在
    @Override
    public boolean isExitById(Classinglog classinglog) {
        ClassinglogExample example = new ClassinglogExample();
        ClassinglogExample.Criteria criteria = example.createCriteria();
        criteria.andIdEqualTo(classinglog.getId());

        return (classinglogMapper.selectByExample(example)).size()>0?false:true;
    }

    /*
    *   条件查询
    *
     */
    @Override
    public List<Classinglog> getMsgBycondition(Classinglog classinglog) {
        ClassinglogExample example = new ClassinglogExample();
        ClassinglogExample.Criteria criteria = example.createCriteria();
        criteria.andOptnameLike("%"+classinglog.getOptname()+"%");
        criteria.andOpttimeLike(classinglog.getOpttime()+"%");
        criteria.andRmcodeLike(classinglog.getRmname()+"-%");

        List<Classinglog> list = classinglogMapper.selectByExample(example);
        System.out.println("数据长度："+list.size());
        return list;
    }

    @Override
    public int countType() {
        return classinglogMapper.countType();
    }

    @Override
    public int countType2() {
        return classinglogMapper.countType2();
    }

    @Override
    public int countType3() {
        return classinglogMapper.countType3();
    }


}
